package org.example.config.componentscan;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.Arrays;

/**
 * 1. 仅用@SpringBootApplication，跟踪代码至 {@link org.springframework.context.annotation.ComponentScanAnnotationParser#parse}
 * 2. 打开@ComponentScan注释，跟踪代码至 {@link org.springframework.context.annotation.ComponentScanAnnotationParser#parse}
 */
@SpringBootApplication
//@ComponentScan("org.example.config.componentscan.package1")
//@ComponentScan("org.example.config.componentscan.package1")
//@ComponentScan("org.example.config.componentscan.package2")
//@ComponentScan("org.example.config.componentscan.package2")
public class ComponentScanApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ComponentScanApplication.class, args);
        Arrays.stream(context.getBeanDefinitionNames()).filter(name -> name.startsWith("mock")).forEach(System.out::println);
        context.close();
    }
}